<extend name="./Base/base" />

<block name="main">
	<div class="row" style="margin-left:300px; ">
			<div class="col-sm-6">	
				<form action="" method="post">	
				<div class="panel">
					<div class="panel-heading bk-bg-primary">
						<h6><i class="fa fa-indent red"></i>管理员添加</h6>							
					</div>
					<div class="panel-body">
						<div class="form-group has-success">
							<label class="control-label" for="inputSuccess1">管理员名称</label>
							<input type="text" class="form-control" name="username" id="inputSuccess1">
						</div>
						<div class="form-group has-warning">
							<label class="control-label"  for="inputWarning1">密码</label>
							<input type="password" name="password" class="form-control" id="inputWarning1">
						</div>
						<div class="form-group has-warning">
							<label   for="inputWarning1">确认密码</label>
							<input type="password" name="repassword" class="form-control" id="inputWarning2">
						</div>
						<div class="form-group has-error">
							<label class="control-label"   for="inputError1">邮箱</label>
							<input type="email" name="email" class="form-control" id="inputError1" >
						</div>
						<!-- <input type="submit" id="login_user" class="btn btn-inverse" value="提交"> -->
						<div id="message" style="margin-left:115px;"></div>
					</div>
					<!--  <button  id="login" class="btn btn-success">提交</button> -->
					<button  class="btn btn-large btn-primary" onclick="login_user();return false;" style="margin-left:35%;">&nbsp&nbsp&nbsp&nbsp&nbsp提交&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</button>
				</div>
			</form>
				
			</div>
		
		
	</div>

</block>

<block name="script_user">

	<script type="text/javascript">
			function login_user(){
				var myreg = /^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/;
				var username   = $("input[name='username']").val();
				var password   = $("input[name='password']").val();
				var repassword = $("input[name='repassword']").val();
				var email      = $("input[name='email']").val();
				// alert(username+password+repassword+email);
				if ($("#inputSuccess1").val() == '') {
					$("#message").html('<p class="error" style="color:red">ERROR: 账号不可为空</p>');
                    return false;
				}else if($("#inputWarning1").val() == ''){
					$("#message").html('<p class="error" style="color:red">ERROR: 密码不可为空</p>');
                    return false;
				}else if ($("#inputWarning2").val() == '') {
					$("#message").html('<p class="error" style="color:red">ERROR: 确认密码不可为空</p>');
					return false;
				}else if ($("#inputError1").val() == '') {
					$("#message").html('<p class="error" style="color:red">ERROR: 请填写邮箱</p>');
					return false;
				}else if ($("#inputWarning1").val() != $("#inputWarning2").val()) {
					$("#message").html('<p class="error" style="color:red">ERROR: 二次输入密码不一致</p>');
					return false;
				}
				// $.post("{:U('User/user_update')}",{username:username,password:password,repassword:repassword,email:email}function(data){
				// 	alert('llll');
				// });	
				$.ajax({
					type:"POST",
					url:"{:U('User/user_update')}",
					data:{username:username,password:password,repassword:repassword,email:email},
					success: function(data){
						if (data == 1) {
							alert('异常错误');
						}else if (data == 2) {
							$("#message").html('<p class="error" style="color:red">ERROR: 管理员已存在</p>');
							return false;
						}else if (data == 3) {
							$("#message").html('<p class="error" style="color:red">ERROR: 非法进入,二次输入密码不一致</p>');
							return false;
						}else if (data == 4) {
							$("#message").html('<p class="error" style="color:red">ERROR: 一个邮箱,只能一个账号</p>');
							return false;
						}else{
							
							var res = data.substr(0,1);
							var url = data.substring(2);
							if (res == 5) {
								window.location.href = url;
							};
						}
					}
				});		
			}
			
	</script>
</block>
